import { createRouter, createWebHistory } from "vue-router";

import Home from "../pages/Home.vue";
import News from "../pages/News.vue";
import About from "../pages/About.vue";
import NewsDetail from "../pages/NewsDetail.vue";

const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: "/home", component: Home },
    {
      path: "/news",
      component: News,
      children: [
        {
          name: "NewsDetail",
          path: "detail/:id/:title/:content",
          component: NewsDetail,
          // 第一种写法：将路由收到的所有params参数，作为props传给路由组件
          props: true,

          // 第二种写法：函数写法，自定义需要将什么作为props传递给路由
          /* props(route) {
            return route.params;
          },
          */

          // 第三种写法：对象写法，自定义需要将什么作为props传递给路由
          /*
          props: {
            id:'123',
            title:'标题',
            content:'内容',
          },*/
        },
      ],
    },
    { path: "/about", component: About, name: "about" }, // name: 命名路由
    { path: "/", redirect: "/home" },
  ],
});

export default router;
